import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';

import { BaseHttpService } from '../base-http.service';
import { StudentScoreGrid } from '../student-score/student-score.service';

export interface PublicShared {
  id: number;
  studentid: number;
  begintime: Date;
  endtime: Date;
  shareduid: string;
}

@Injectable({
  providedIn: 'root'
})
export class PublicSharedService {
  apiIndex: string = 'publicshared';
  constructor(private readonly http: BaseHttpService) {}

  public addPublicShared(entity: Partial<PublicShared>): Observable<PublicShared[]> {
    return this.http.post<PublicShared[]>(`/${this.apiIndex}/add`, [entity]);
  }

  public getSharedInfoBySharedUid(sharedUid: string): Observable<StudentScoreGrid[]> {
    return this.http.get<StudentScoreGrid[]>(`/${this.apiIndex}/GetSharedInfo`, {
      uid: sharedUid
    });
  }
}
